<template>
	<view class="content" >
		<image :src="src" :mode="mode" @longpress="toSave"></image>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				src : "",
				mode : "widthFix"
			};
		},
		methods:{
			saveImg(){
				uni.getImageInfo({
					src: this.src,
					success: function(image) {
						uni.saveImageToPhotosAlbum({
							filePath: image.path,
							success: function() {
								uni.showToast({
									title: '图片保存成功',
									icon: 'none',
									duration: 2200
								});
							}
						});
					}
				});
				
			},
			toSave(){
				uni.showModal({
					title: '图片保存',
					content: '确定要保存图片吗',
					success: e => {
						if (e['confirm']) {
							this.saveImg();
						}
					}
				});
			}
			
		},
		onLoad: function(option) {
		    const src = JSON.parse(decodeURIComponent(option.src));
			typeof src != null ? this.src = src : "";
		}
	}
</script>

<style>
	.content{
		position: absolute;
		top: 0;
		bottom: 0;
		width: 100%;
		background-color:rgba(0,0,0,0.3);
		display: flex;
		align-items: center;
	}
	image{
		position: absolute;
		width: 100%;
	}

</style>
